<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>首页</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../../../css/mui.min.css" rel="stylesheet" />
    <link href="../css/common.css" rel="stylesheet" />
    <style>
      /*九宫格样式*/
      *{ touch-action: pan-y; }
      .home_icon {
      	width: 100%;
      }
      
      .mui-icon {
      	width: 100%;
      	padding: 0 26%;
      }
      
      .mui-grid-view.mui-grid-9 {
      	background: #fff;
      	padding: 10px 0;
      }
      
      .mui-grid-view.mui-grid-9 .mui-table-view-cell {
      	border: none;
      	padding: 5px 15px;
      }
      /*图标样式*/
      
      #lineChart {
      	width: 100%;
      	height: 340px;
      	background: #fff;
      	padding: 16px 15px;
      	margin-top: 10px;
      }
      #currentProjectName{
		  background: #fff;text-align: center;
		  padding:10px 0 0;
		  min-height:35px;
		  text-overflow: ellipsis;
		  white-space: nowrap;
		  overflow: hidden;
		  max-width: 100%;
	  }
	  #currentProjectName span{
		  font-size: 14px;color: #666;
		  padding:2px 16px 0;
		  border:1px solid #ccc;
		  border-radius: 20px;
	  }
    </style>
  </head>
  <body>
    <div id="container">
      <!--
      <header class="mui-bar mui-bar-nav">
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
        <h1 class="mui-title">外来人员管理</h1>
      </header>
	  -->
      <div class="mui-content">
        <div id="slider" class="mui-slider">
          <div class="mui-slider-group mui-slider-loop">
            <!-- 额外增加的一个节点(循环轮播：第一个节点是最后一张轮播) -->
            <div class="mui-slider-item mui-slider-item-duplicate">
              <a href="javascript:;">
                <img src="../img/img.png">
              </a>
            </div>
            <!-- 第一张 -->
            <!-- <div class="mui-slider-item">
                <a href="#">
                  <img src="../img/img.png">
                </a>
              </div> -->
            <!-- 第二张 -->
            <!-- <div class="mui-slider-item">
                <a href="#">
                  <img src="../img/img.png">
                </a>
              </div> -->
            <!-- 第三张 -->
            <!-- <div class="mui-slider-item">
                <a href="#">
                  <img src="../img/img.png">
                </a>
              </div> -->
            <!-- 第四张 -->
            <!-- <div class="mui-slider-item">
                <a href="#">
                  <img src="../img/img.png">
                </a>
              </div> -->
            <!-- 额外增加的一个节点(循环轮播：最后一个节点是第一张轮播) -->
            <!-- <div class="mui-slider-item mui-slider-item-duplicate">
                <a href="#">
                  <img src="../img/img.png">
                </a>
              </div> -->
          </div>
          <div class="mui-slider-indicator">
            <div class="mui-indicator mui-active"></div>
            <!--
              <div class="mui-indicator"></div>
              <div class="mui-indicator"></div>
              <div class="mui-indicator"></div>
			  -->
          </div>
        </div>
		<div id="currentProjectName">
			
		</div>
        <ul class="mui-table-view mui-grid-view mui-grid-9" style="border-top: none;">
          <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="project">
            <a href="#">
              <span class="mui-icon ">
                <img src="../img/project.png" class="home_icon" />
              </span>
              <div class="mui-media-body">关联项目</div>
            </a>
          </li>
          <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="course">
            <a href="#">
              <span class="mui-icon ">
                <img src="../img/course.png" class="home_icon" />

              </span>
              <div class="mui-media-body">我的课程</div>
            </a>
          </li>
          <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="exam">
            <a href="#">
              <span class="mui-icon ">
                <img src="../img/reusult.png" class="home_icon" />
              </span>
              <div class="mui-media-body">考试</div>
            </a>
          </li>
          <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="safe">
            <a href="#">
              <span class="mui-icon ">
                <img src="../img/safe.png" class="home_icon" />

              </span>
              <div class="mui-media-body">手签文档</div>
            </a>
          </li>
		  <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="notice">
		    <a href="#">
		      <span class="mui-icon ">
		        <img src="../img/notice.png" class="home_icon" />
		  
		      </span>
		      <div class="mui-media-body">入场须知</div>
		    </a>
		  </li>
		  <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="meetingScan">
		    <a href="#">
		      <span class="mui-icon ">
		        <img src="../img/scan.png" class="home_icon" />
		  
		      </span>
		      <div class="mui-media-body">班会扫码</div>
		    </a>
		  </li>
		  <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4">
		    <a href="#popover">
		      <span class="mui-icon ">
		        <img src="../img/group_home_2.png" class="home_icon" />
		  
		      </span>
		      <div class="mui-media-body">操作说明</div>
		    </a>
		  </li>
		  <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4">
		    <a href="../../mqms/login.html?source=out">
		      <span class="mui-icon ">
		        <img src="../img/group_home_7.png" class="home_icon" />
		      </span>
		      <div class="mui-media-body">检修质量</div>
		    </a>
		  </li>
        </ul>
      </div>
	  
	  <div id="popover" class="mui-popover">
	    <ul class="mui-table-view">
	      <li class="mui-table-view-cell"><a href="#">第一步：关联项目并通过审核。</a></li>
	      <li class="mui-table-view-cell"><a href="#">第二步：观看课程</a></li>
	      <li class="mui-table-view-cell"><a href="#">第三步：参加考试</a></li>
	      <li class="mui-table-view-cell"><a href="#">第四步：完成手签文档</a></li>
	      <li class="mui-table-view-cell"><a href="#">第五步：进入入场须知登记</a></li>
		  <li class="mui-table-view-cell"><font size="2" color="#999999">备注：如果关联项目小于10天（含10天），则不需要进行考试。</font></li>
	    </ul>
	  </div>
  </body>

  <script src="../../../js/mui.min.js"></script>
  <script src="../../../js/jquery-1.7.2.min.js"></script>
  <script src="../../../js/vue.js"></script>
  <script src="../js/mkeyplus.base.js"></script>
  <script src="../formal/js/api.js"></script>
  <script type="text/javascript" charset="utf-8">
    var htapi = new HTGlobal();
    var daysStatus=null;//是记录项目工作时长的，预计工期时长：1，大于10天；2，小于等于10天
    var appUserId="";//当前用户id
	var projectAuditStatus = false;//当前项目是否审核
    mui.init({
      swipeBack: true //启用右滑关闭功能
    });
    var slider = mui("#slider");
    /*	
        slider.slider({
          interval: 3000
        });
		*/
	var unifyfn = function(action){//action();return;
		if(daysStatus){
			getCourseStatus(function(data){
			  if(data){
				  if(daysStatus==1){
					  getExamStatus(function(res){
					    if(res){
							action()
						}
					  })
				  }else if(daysStatus==2){
					  action()
				  }
			  }
			})
		}else{
			mui.toast('请先关联项目，并等待通过审核！')
		}
		return;
	}
	//班会扫码
	var barScan = undefined,
	barScanClose = function(){
		if(barScan){
			barScan.close();
			plus.webview.currentWebview().remove(barScan)
			barScan = undefined
		}
	},
	barScanCallback = function(mid){
		mui.openWindow({
		  url: './meeting-scan.html',
		  id: 'meeting-scan',
		  extras: {
			  mid:mid
		  },
		  waiting: {
		    autoShow: false
		  },
		})
	}
	$('#meetingScan').on('tap',function(){
		barScan = plus.barcode.create('barcode', [plus.barcode.QR], {
		    top:'0',
		    left:'0',
		    width: '100%',
		    height: '100%',
		    position: 'static'
		});
		plus.webview.currentWebview().append(barScan);
		barScan.start({conserve:true}); 
		barScan.onmarked = function(type,code,file){
		    barScanClose()
			barScanCallback(code)
		    return false
		}
	})
	
    
    $('#project').on('tap', function() {
		//关联项目
      mui.openWindow({
        url: '../project/project.html',
        id: '../project/project.html',
        extras: {},
        waiting: {
          autoShow: false
        }
      })
    });
    $('#notice').on('tap', function() {
		getCourseStatus(function(data){
		//入场须知
		if(data)
		mui.openWindow({
		  url: './home-notice.html',
		  id: './home-notice.html',
		  extras: {},
		  waiting: {
		    autoShow: false
		  }
		})
		})
    });
	
    $('#safe').on('tap', function() {
		getCourseStatus(function(data){
		//手签文档
		if(data)
		mui.openWindow({
		  url: './home-safe.html',
		  id: './home-safe.html',
		  extras: {},
		  waiting: {
		    autoShow: false
		  }
		})
		})
    });
    $('#course').on('tap', function() {
		if(!checkProjectAuditStatus())return;
		//我的课程
      mui.openWindow({
        url: '../course/myCourse.html',
        id: '../course/myCourse.html',
        extras: {},
        waiting: {
          autoShow: false
        }
      })
    });
    $('#exam').on('tap', function() {
      getCourseStatus(function(data){//完成课程观看后才能去考试
        if(data){
          mui.openWindow({
            url: '../course/courseNew.html',
            id: '../course/courseNew.html',
            extras: {},
            waiting: {
              autoShow: false
            }
          })
        }
      }) 
    });
    var first = null; //第一次点击backbutton
    mui.plusReady(function() {
      var new_back = mui.back;
      mui.back = function() {
		barScanClose();
        //首次按键，提示‘再按一次退出应用’
        if (!first) {
          first = new Date().getTime();
          mui.toast('再按一次退出应用');
          setTimeout(function() {
            first = null;
          }, 800);
        } else {
          if (new Date().getTime() - first < 1000) {
            plus.runtime.quit();
          }
        }
      }
      var user = htapi.getOsUser();
      //alert(JSON.stringify(user));
      appUserId=user.id;
      getStatus(user.id,toUpdateStatus)
      // getExamStatus()
	  getArea();
	 
    })
	
	function getArea(){
		mui.baseWApp.httpRequst("/runLog/j/getAreaStation", {
		}, function(data) {
			console.log('xxxxxxxx......',JSON.stringify(data));
		}, function() {
		  console.log("获取数据失败");
		})
	}
	function checkProjectAuditStatus(){
		/** 项目是否通过审核
		 * @method checkProjectAuditStatus
		 * @param {空}
		 * @return 
		*/
		if(!projectAuditStatus){
			mui.alert('您关联的项目人员信息未经过审核，请联系场站负责人审核，场站操作步骤：关联项目审核->查看->工作人员->待审核人员。')
			return false;
		}
		return true
	}
	function toUpdateStatus(data){
		console.log('.......data.........',JSON.stringify(data));
		/** 更改当前项目信息
		 * @method toUpdateStatus
		 * @param {data}
		 * @return {空} 
		*/
		if(data.code=='0'){
			var D = data.data
			var dom = $('#currentProjectName')
			
			dom.html('<span>当前项目：'+D.currentProjectName+'</span>')
			projectAuditStatus = false
			if(D.auditStatus==3 && !D.isTech || (D.auditStatus==5 && D.isTech)) {
				projectAuditStatus = true
			}
		}
		return 
	}
	window.addEventListener('setCurrentProjectName',function(data){
		var user = htapi.getOsUser();
		getStatus(user.id,toUpdateStatus)
		return;
	},false)
    function getStatus(id,callback){
		htapi.synchronizationUserInfo(function(data){
			console.log('获取天数'+ JSON.stringify(data))
			if(data.code=='0'){
			  daysStatus=data.data.daysStatus || 1
			  // daysStatus=2
			}else{
				//alert(JSON.stringify(data))
			}
			if(callback && typeof(callback)=='function'){
				callback(data)
			}
		})
    }
    function getCourseStatus(callback){//获取课程状态
		if(!checkProjectAuditStatus())return;
      var Status=false;
	  plus.nativeUI.showWaiting('请稍后');
      mui.baseWApp.httpRequst("/outsider/app/course/findCourseStatus/" + appUserId, {
      }, function(data) {
		  plus.nativeUI.closeWaiting();
        console.log('获取课程状态'+ JSON.stringify(data))
        if(data.code=='0'){
          Status=true; 
        }else{
          Status=false
          mui.toast(data.msg) 
        }
        callback(Status);
      }, function() {
        plus.nativeUI.closeWaiting();
        console.log("获取数据失败");
      })
      
    }
     function getExamStatus(callback){//获取考试状态
      var Status=false;
      mui.baseWApp.httpRequst("/outsider/app/exam/findExamStatus/" + appUserId, {
      }, function(data) {
        console.log('获取考试状态'+ JSON.stringify(data))
        if(data.code=='0'){
          Status=true; 
        }else{
          Status=false
          mui.toast(data.msg) 
        }
        callback(Status);
      }, function() {
        plus.nativeUI.closeWaiting();
        console.log("获取数据失败");
      })
    }
  </script>

</html>
